//
// Created by Administrator on 2025/3/18.
//

#include "ui_elf_game_common.h"
ui_elf_game_main_screen_t ui_elf_game_main_screen = {0};
elf_game_module_t elf_game_module = {.data=&elf_game_data,.screen=&ui_elf_game_main_screen};

// 宠物信息页面飘字
lv_obj_t *ui_elf_flutter_panel(lv_obj_t *parent,char *word){
    // 飘字 pos x: 81, y: 47
    lv_obj_t *flutter_img = ui_create_default_image_by_src(parent, &elf_flutter_word_img);
    lv_obj_align(flutter_img, LV_ALIGN_TOP_LEFT, 81, 47);
    // 很开心，今天 又是元气满满 的一天
    lv_coord_t flutter_label_width = 100;
    lv_obj_t *flutter_label_panel = ui_create_without_flex_panel(flutter_img, flutter_label_width, 54);
//        lv_obj_t *flutter_label_panel = ui_create_without_flex_panel(flutter_img, 94, 80);
    lv_obj_set_style_bg_opa(flutter_label_panel, LV_OPA_0, 0);
    lv_obj_t *flutter_label = ui_create_default_label(flutter_label_panel, word,
                                                      CHINESE_FONT_16_LIGHT);
    lv_obj_set_style_text_color(flutter_label, lv_color_white(), 0);
    // 设置宽度才能换行
    lv_obj_set_width(flutter_label, flutter_label_width);
    lv_label_set_long_mode(flutter_label, LV_LABEL_LONG_WRAP);
    lv_obj_set_style_text_align(flutter_label, LV_TEXT_ALIGN_CENTER, 0);
    return flutter_img;
}

// 隐藏当前屏幕
void ui_elf_hide_current_screen(){
    lv_obj_add_flag(elf_game_module.screen->screen, LV_OBJ_FLAG_HIDDEN);
    elf_game_module.screen->last_screen = elf_game_module.screen->screen;
    elf_game_module.screen->last_group = elf_game_module.screen->group;
    elf_game_module.screen->last_deinit_cb = elf_game_module.screen->deinit_cb;
    elf_game_module.screen->screen = NULL;
    elf_game_module.screen->group = NULL;
    elf_game_module.screen->deinit_cb = NULL;
}

//恢复上一个屏幕
void ui_elf_refresh_last_screen(){
//    ui_screen_group_deinit_common(&(elf_game_module.screen->screen), &(elf_game_module.screen->group));
    elf_game_module.screen->deinit_cb();
    elf_game_module.screen->screen = elf_game_module.screen->last_screen;
    elf_game_module.screen->group = elf_game_module.screen->last_group;
    elf_game_module.screen->deinit_cb = elf_game_module.screen->last_deinit_cb;
    lv_obj_clear_flag(elf_game_module.screen->screen, LV_OBJ_FLAG_HIDDEN);
    lv_group_set_default(elf_game_module.screen->group);
    lv_indev_set_group(indev_keypad, elf_game_module.screen->group);
    elf_game_module.screen->last_screen = NULL;
    elf_game_module.screen->last_group = NULL;
    elf_game_module.screen->last_deinit_cb = NULL;
}